import 'package:bmprogresshud/bmprogresshud.dart';
import 'package:car_baidu/core/constant/initialize_data.dart';
import 'package:car_baidu/core/router/router.dart';
import 'package:car_baidu/ui/shared/theme/app_theme.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '../../smipeapp/lib/size_fit.dart';
import 'core/viewmodel/config/prvoider_config.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // 初始化数据
    LLInitializeData.initialize();
    // 初始化尺寸
    LLSizeFit.initialize();

    return FutureBuilder(
        future: LLInitializeData.initialize(),
        builder: (context, AsyncSnapshot<bool> snapshot) {
          if (snapshot.data == true) {
            // 初始化路由
            LLRouter.initialize();
            return ProgressHud(
              isGlobalHud: true,
              child: MultiProvider(
                // 数据共享
                providers: mainProvider,
                child: MaterialApp(
                  title: "车佰度",
                  // 主题相关
                  theme: LLAppTheme.lightData,
                  darkTheme: LLAppTheme.lightData,
                  // 路由相关
                  initialRoute: LLRouter.initialRouter,
                  routes: LLRouter.routers,
                  onGenerateRoute: LLRouter.onGenerateRoute,
                  onUnknownRoute: LLRouter.onUnknownRoute,
                ),
              ),
            );
          } else {
            return Container(
              width: double.infinity,
              height: double.infinity,
              color: Colors.red,
            );
          }
        });
  }
}
